<?php


namespace app\common\model;


use think\Model;

class UserAmountRewardDetailed extends Model
{
    //赏金账户资金明细列表
    public static function UserAmountRewardDetailedList($where,$pageIndex,$pageSize){
        return self::where($where)->order('id desc')->page($pageIndex,$pageSize)->select();
    }

    //用户邀请下级-奖励列表
    public static function rewardDetailsList($page,$num,$where,$field="ua.*,u.nickname"){
        return self::alias("ua")
            ->leftJoin("user u","u.uid=ua.below_id")
            ->where($where)
            ->field($field)
            ->group("ua.id")
            ->order("ua.addtime desc")
            ->page($page,$num)
            ->select();
    }

    public static function rewardDetailsCount($where,$field="ua.*,u.nickname"){
        return self::alias("ua")
            ->leftJoin("user u","u.uid=ua.below_id")
            ->where($where)
            ->field($field)
            ->group("ua.id")
            ->count();
    }

    //赏金账户资金明细统计
    public static function UserAmountRewardDetailedCount($where){
        return self::where($where)->count();
    }

    //赏金账户资金明细记录
    public static function UserAmountRewardDetailedAdd($data){
        return self::create($data);
    }

    //赏金账户资金明细批量记录
    public static function UserAmountRewardDetailedAddAll($data){
        return self::insertAll($data);
    }
    
    //赏金账户资金明细金额
    public static function UserAmountRewardDetailedBagSurplus($where){
        return self::field('sum(amount_money) as bagSurplus')->where($where)->find();
    }

    //下单会员奖励统计
    public static function orderRewardSum($where, $value)
    {
        return self::where($where)->sum($value);
    }
}